package calao.client.ui;

import java.util.Iterator;

import calao.client.util.IntMap;

public class MappedListBox
extends NumberedListBox
{
	
	final IntMap itemMap;
	int[] numbers;
	
	public MappedListBox(IntMap itemMap, int type)
	{
		super(type);
		this.itemMap = itemMap;
	}
	
	public void refresh()
	{
		numbers = new int[itemMap.size()];
		Iterator iter = itemMap.keySet().iterator();
		int count = 0;
		while (iter.hasNext()) {
			numbers[count++] = ((Integer)iter.next()).intValue();
		}
		super.refresh();
	}
	
	public MappedListBox(IntMap itemMap)
	{
		this(itemMap, DROPDOWN_LIST);
	}
	
	protected String getItemText(Object item)
	{
		return item.toString();
	}

	final protected int getItemCount() 
	{
		return numbers.length;
	}

	final protected long getItemNumber(int index) 
	{
		return numbers[index];
	}

	final protected String getItemText(int index) 
	{
		return getItemText(getItem(index));
	}

	final public Object getItem(int index)
	{
		return itemMap.get(numbers[index]);
	}

}
